#include "PlayList.h"
#include "common.h"

wxString listMarker = wxString::FromAscii("#aychip playlist. thanks to andrew for libayfly. gritz all zx fanz!");

PlayListItem* PlayList::addItem(wxString path) {
	PlayListItem *item = new PlayListItem(path);
	if (!item->isChipModule) {
		delete item;
		return 0;	/// no item!
	}
	items.push_back(item);
	return item;
}

PlayListItem* PlayList::addItemFast(wxString path, wxString dispInfo, int duration) {
	PlayListItem *item = new PlayListItem(path, dispInfo, duration);
	items.push_back(item);
	return item;
}



PlayList::PlayList() {
	items.clear();
}

PlayList::PlayList(wxString pathToExistingFileList) {
	open(pathToExistingFileList);
}

int PlayList::open(wxString path) {
///	wxFile openList(path, wxFile::read);
	// check for file format, if unsupported, then dummy
	return 0;
}

PlayListItem* PlayList::getFirstItem() {
	if (items.size() > 0) return items[0];
	 else return 0;
}

int PlayList::save(wxString path) {
	wxTextFile saveList(path);
	PLItem::iterator it = items.begin();
	saveList.AddLine(listMarker);
	while(it!=items.end()) {
		saveList.AddLine((*it)->path);
		saveList.AddLine(wxString::Format(_T("%d"), (*it)->duration));
		saveList.AddLine((*it++)->displayInfo);
	}
	saveList.Write();
	saveList.Close();
	return 0;
}

